package com.tiany.java_study_exercise;

public class Student {
    int number;//学号
    int state;//年级
    int score;//成绩

    //生成学生信息
    public Student[] random_info() {
        Student[] stu = new Student[20];//20个学生
        for (int i = 0; i < 20; i++) {
            stu[i] = new Student();
            stu[i].number = (i + 1);
            stu[i].state = (int) (Math.random() * (6 - 1 + 1) + 1);
            stu[i].score = (int) (Math.random() * (100) + 1);
        }
        return stu;
    }


    //打印全部学生信息
    public void print_all(Student[] stu) {
        System.out.println("***************学生信息如下*********************");
        for (Student student : stu) {
            System.out.println("学号：" + student.number + "   年级：" + student.state + "   成绩：" + student.score);
        }
    }

    //打印特顶年级学生信息
    public void print_state(Student[] stu, int state) {
        System.out.println("***************" + state + "班成绩如下**************************");
        for (Student student : stu) {
            if (student.state == state) {
                System.out.println("学号：" + student.number + "   成绩：" + student.score);
            }
        }
    }

    //对学生成绩排序
    public void sort(Student[] stu) {
        for (int i = 0; i < stu.length - 1; i++) {
            for (int j = 0; j < stu.length - 1; j++) {
                if (stu[j].score > stu[j + 1].score) {
                    Student tmp = stu[j];
                    stu[j] = stu[j + 1];
                    stu[j + 1] = tmp;
                }
            }
        }
        System.out.println("********************排序如下******************");
        for (int i = 0; i < 20; i++) {
            System.out.println("学号：" + stu[i].number + "   年级：" + stu[i].state + "   成绩：" + stu[i].score);
        }

        //
    }
}
